home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- event.c contains routines servicing the Mac event loop, along
- with other routines supporting MultiFinder etc.
- The text selection copy/print selection routines are also included here.
-
- */
-
- #include <em.h>
-
- #include <3270.h>
- #include <rcodes.h>
- #include <h19.h>
- #include <errors.h>
- #include <util.h>
- #include <macdefs.h>
- #include <resdefs.h>
- #include <cntldefs.h>
- #include <config.h>
- #include "menudefs.h"
-
- #include <ctype.h>
-
- #define KEYPDIAL /* use a dialog for keypad selection */
-
- short mousecurson; /* is the mouse cursor drawn? */
- short modaldialog; /* is a modaldialog active outside the Mac task? skip event loop! */
- long creator = '3278'; /* creator for file info */
-
- short autokey; /* key is in auto mode */
- short autokeycommand; /* autoKey menu commands use this flag to suppress menu flashing */
- short autokeypersist; /* indicates autokey has been on */
- timer *autokeywait;
- extern int clrautokeywait();
-
- char fileopenerr[] = "Error opening file";
- char filecreateerr[] = "Error creating file";
- char filewriteerr[] = "Error writing to file";
- char untitled[] = "\PUntitled";
- char copyerr[] = "to perform copy";
-
- unsigned long mousedelay; /* keeps last tick for double-click */
- short doubleclick; /* a double click occurred */
- short mfpresent = TRUE; /* we're under MultiFinder */
- short mfbackground; /* we're in the background under MultiFinder */
-
- Handle scraptemp; /* used for Scrap Appends */
-
- extern DialogPtr nnrdptr; /* network not responding */
-
- /* stuff now in menu.c */
- extern MenuHandle menu[];
- extern char scrapzeroed; /* has scrap been zeroed yet? */
-
- extern short darefnum;
- extern PicHandle iconpict;
-
- pascal void RepAction();
-
- clrautokeywait()
- {
- autokeypersist = FALSE;
- }
-
- /* the BIG EVENT LOOP! */
-
- user_act()
- {
- while (TRUE) {
- SystemTask(); /* keep this if/until we use WaitNextEvent */
-
- if (cutcpopen)
- datayield();
-
- if (modaldialog)
- return(-1);
-
- /* get all Macintosh events waiting in the queue */
- /* before doing tn key handling */
- if ( ! GetNextEvent(everyEvent, &myEvent)) {
- /* ignore system events */
- if (myEvent.what == nullEvent) {
- /* out of events, go around loop and yield */
- return(0);
- }
- else
- /* get the next event */
- continue;
- }
- if (IsDialogEvent(&myEvent)) {
- /* the net not responding dialog is up--net/nnr.c */
- short itemhit;
-
- if (myEvent.what == mouseDown) {
- /* bring up keywindow, ignore the mouseDown */
- selectwindow(keywindow);
- continue;
- }
- else if (DialogSelect(&myEvent, &nnrdptr, &itemhit))
- /* ignore dialog events handled by Dialog Mgr */
- continue;
- }
- switch (myEvent.what) {
- case nullEvent: {
- /* out of events, return */
- return(0);
- }
- case diskEvt: {
- diskevent(&myEvent);
- break;
- }
- case networkEvt: {
- /* appletalk network event has occured */
- break;
- }
- case app4Evt: {
- /* suspend/resume events */
- mfswitch(&myEvent);
- break;
- }
- case autoKey:
- autokey = TRUE;
- if (myEvent.modifiers & cmdKey)
- autokeycommand = TRUE;
-
- if (autokeywait == NULL) {
- /* allocate a timer to maintain autokeypersist */
- autokeywait = tm_alloc();
- }
- if (autokeywait != NULL) {
- autokeypersist = TRUE;
- tm_tset(60, clrautokeywait, NULL, autokeywait);
- }
-
- case keyDown: {
- unsigned char thechar;
- unsigned char keycode;
- long comm;
-
- thechar = myEvent.message & 0xff;
- keycode = (myEvent.message >> 8) & 0xff;
- if (keydp) {
- #ifdef USETEXTWINDOWS
- if (FrontWindow() == keydp->textwindow) {
- /* text window is up, put keystrokes in it... */
-
- if (keydp->texthand == NULL)
- break;
- if (myEvent.modifiers & cmdKey
- && keycode < 52
- && !(myEvent.modifiers & optionKey)
- && !(myEvent.modifiers & ctrlKey)
- ) {
- /* of the modifier keys, only the command key/caps lock are down */
- /* and the keycode is less than the keypad codes */
- /* is this a menu key ? */
- if (thechar == '.') {
- /* user wants to abort actions */
- flushactions(keydp);
- break;
- }
- else if (comm = MenuKey(thechar)) {
- docommand(comm);
- }
- break;
- }
- TEKey(thechar, keydp->texthand);
-
- /* Hornig: make sure selection in in view */
- textctlupd(keydp);
- SelView(keydp);
- }
- else
- #endif
- {
- if (keydp->termset && !keydp->icon_up) {
- /* do emulator keymapping */
- keymap(keycode, thechar, myEvent.modifiers);
- }
- else {
- /* We have no concept of who we are yet!
- Do not interfere with Telnet negotiations!
- do menus though...*/
-
- if (myEvent.modifiers & cmdKey
- && keycode < 52
- && !(myEvent.modifiers & optionKey)
- && !(myEvent.modifiers & shiftKey)
- && !(myEvent.modifiers & ctrlKey)
- ) {
- /* of the modifier keys, only the command key/caps lock are down */
- /* and the keycode is less than the keypad codes */
- /* is this a menu key ? */
- if (thechar == '.') {
- /* user wants to abort actions */
- flushactions(keydp);
- break;
- }
- else if (comm = MenuKey(thechar)) {
- docommand(comm);
- }
- }
- else if (keydp->icon_up) {
- /* ignore keystrokes when the window is shrunk */
- beep();
- break;
- }
- break;
- }
- }
- }
- else {
- /* do menu commands only */
- if (comm = MenuKey(thechar)) {
- docommand(comm);
- }
- }
- if (autokey)
- /* break out of event loop so other stuff gets serviced */
- return(0);
- break;
- }
- case keyUp: {
- if (autokeycommand) {
- autokeycommand = FALSE;
- HiliteMenu(0);
- }
- autokey = FALSE;
- break;
- }
- case mouseUp: {
- mousedelay = cticks;
- break;
- }
- case mouseDown: {
- short windowpart;
- WindowPtr clickwind;
- struct winds * twp;
-
- windowpart = FindWindow(pass(myEvent.where), &clickwind);
-
- if (clickwind != NULL)
- twp = ((WindowPeek) clickwind)->refCon;
- /* this must be one of the keydp context window members */
- switch (windowpart) {
- case inGoAway: {
- /* do the right thing to close a window */
- #ifdef USETEXTWINDOWS
- if (clickwind == twp->textwindow) {
- HideWindow(twp->textwindow);
- selectwindow(twp->emwindow);
- twp->hidetextwindow = TRUE;
- }
- else
- #endif
- menufile(WMCLOSEWIND); /* handle through menu routine */
- break;
- }
- case inMenuBar: {
- docommand(MenuSelect(pass(myEvent.where)));
- break;
- }
- case inSysWindow: {
- SystemClick(&myEvent, clickwind);
- break;
- }
- case inDrag: {
- Point thept;
- Point oldpoint;
-
- SetPort(clickwind);
- thept.v = clickwind->portRect.top;
- thept.h = clickwind->portRect.left;
- LocalToGlobal(&thept);
- oldpoint = thept;
-
- if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- }
- DragWindow(clickwind, pass(myEvent.where), &dragrect);
-
- if (((WindowPeek) clickwind)->windowKind == EMWINDKIND) {
- thept.v = clickwind->portRect.top;
- thept.h = clickwind->portRect.left;
- LocalToGlobal(&thept);
- alignwind(twp, (thept.h < oldpoint.h) ? TRUE : FALSE);
- /* shift left if that was the direction of drag */
-
- testds(twp);
-
- #ifdef MOVETEXTWIND
- thept.v = clickwind->portRect.top;
- thept.h = clickwind->portRect.left;
- LocalToGlobal(&thept);
-
- /* now drag the textwindow along with it */
- textwmove(twp, (thept.h - oldpoint.h), (thept.v - oldpoint.v));
- #endif
- }
- break;
- }
- case inZoomIn:
- case inZoomOut: {
- if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- break;
- }
- if (TrackBox(clickwind, pass(myEvent.where), windowpart)) {
- shrinkwindow(keydp);
- /* change the window font size
- menuctrl(MSCREENSIZE);
- */
- }
- break;
- }
- case inGrow:
- case inContent: {
- unsigned clicktime = cticks - mousedelay;
-
- if (((WindowPeek) clickwind)->windowKind == ICONWINDKIND) {
- if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- DragWindow(clickwind, pass(myEvent.where), &dragrect);
- }
- else if (clicktime <= GetDblTime()) {
- /* a candidate double click, we would do it on mouseUp to be like Finder
- BUT the mouseUp event NEVER ARRIVES!!!??? */
-
- #ifdef USETEXTWINDOWS
- expandwindow(twp);
- #else
- selectwindow(twp->emwindow);
- ShowWindow(twp->emwindow);
- HideWindow(iconwindow);
-
- keydp->icon_up = FALSE; /* restore keyboard */
- keydp->iconhigh = FALSE;
- #endif
-
- shownnr(); /* if "net not receiving" is up, show it */
- }
- else
- DragWindow(clickwind, pass(myEvent.where), &dragrect);
- mousedelay = cticks;
- }
- else if (((WindowPeek) clickwind)->windowKind == EMWINDKIND) {
- /* we're in keywindow, routines assume this */
- if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- }
- else {
- SetPort(twp->emwindow);
- if (clicktime <= GetDblTime())
- doubleclick = TRUE;
- else
- doubleclick = FALSE;
- mousedelay = cticks + clickdelay;
- /* more time is needed due to delay in emmouseclick() */
-
- GlobalToLocal(&myEvent.where);
- emmouseclick(&myEvent.where);
- }
- }
- #ifdef USETEXTWINDOWS
- else if (((WindowPeek) clickwind)->windowKind == TEXTWINDKIND) {
- ControlHandle theCtlHand;
-
- if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- break;
- }
- SetPort(twp->textwindow);
- if (keydp->texthand == NULL)
- break;
- #ifdef SIZETEXTWINDOW
- if (windowpart == inGrow) {
- /* resize the window */
- Rect growrect;
- unsigned long growth;
-
- getcontext(twp);
-
- /* set min/max grow limits */
- growrect.top = 50;
- growrect.left = 50;
- growrect.bottom = 32000;
- growrect.right = 32000;
-
- growth = GrowWindow(twp->textwindow,
- pass(myEvent.where),
- &growrect);
- textwsize((short) (growth & 0x0000FFFF),
- (short) ((growth >> 16) & 0x0000FFFF));
- break;
- }
- #endif
- GlobalToLocal(&myEvent.where);
- if (PtInRect(pass(myEvent.where), &(*twp->texthand)->viewRect)) {
- /* in text */
- TEClick(pass(myEvent.where), (myEvent.modifiers & shiftKey) ? TRUE : FALSE, twp->texthand);
- }
- /* else check scrollbar, Hornig code */
- else if( FindControl( pass(myEvent.where), clickwind, &theCtlHand ) )
- {
- if( TestControl( theCtlHand, pass(myEvent.where) ) == inThumb )
- { /* scroll bar inThumb requires special TrackControl */
- if( TrackControl( theCtlHand, pass(myEvent.where), NULL ) )
- MoveElevator( theCtlHand );
- }
- else TrackControl( theCtlHand, pass(myEvent.where), (ProcPtr) RepAction );
- }
- }
- #endif
- #ifdef USEHELPWINDOW
- else if (((WindowPeek) clickwind)->windowKind == HELPWINDKIND) {
- if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- break;
- }
- helpwhandle();
- }
- #endif
- else if (clickwind != FrontWindow()) {
- selectwindow(clickwind);
- }
- break;
- }
- }
- break;
- }
- case activateEvt: {
- activatewind();
- break;
- }
- case updateEvt: {
- updatewind();
- break;
- }
- }
- /* break; just do loop once */
- }
- }
-
-
- activatewind()
- {
- GrafPtr oldport;
- WindowPtr actwind;
- int menuredraw = FALSE;
- struct winds * twp;
-
- actwind = myEvent.message;
- twp = ((WindowPeek) actwind)->refCon;
- if (((WindowPeek) actwind)->windowKind == EMWINDKIND) {
- if (myEvent.modifiers & activeFlag) {
- keywindow = actwind;
- keydp = ((WindowPeek) keywindow)->refCon;
- iconwindow = keydp->iconwindow;
- twp->edit = FALSE;
-
- SetPort(keywindow);
-
- /* do menu stuff */
- menuredraw = menucheck(keydp);
-
- /* TODO what about bkrd_act when textwindow or iconwindow
- comes up? should be reset? */
- bkrd_act = 0;
- testds(keydp);
-
- }
- else {
- emwdeactivate();
- }
- }
- #ifdef USETEXTWINDOWS
- else if (((WindowPeek) actwind)->windowKind == TEXTWINDKIND) {
- /* make the associated emulator window the key window */
- if (myEvent.modifiers & activeFlag) {
- keywindow = actwind;
- keydp = ((WindowPeek) keywindow)->refCon;
- iconwindow = keydp->iconwindow;
- twp->edit = TRUE;
-
- SetPort(keywindow);
-
- if (twp->texthand) {
- TEActivate(twp->texthand);
- scraptote();
- twp->textscrapped = FALSE;
-
- ShowControl(twp->vBarHand);
- }
- menuredraw = menucheck(keydp);
- }
- else {
- if (twp->texthand) {
- TEDeactivate(twp->texthand);
- HideControl(twp->vBarHand);
- if (twp->textscrapped) {
- tetoscrap(*TEScrHandle, TEScrLen);
- twp->textscrapped = FALSE;
- }
- }
- }
- drawgrowicon(actwind);
- }
- #endif
- #ifdef USEHELPWINDOW
- else if (((WindowPeek) actwind)->windowKind == HELPWINDKIND) {
- helpwhandle();
- }
- #endif
- else if (((WindowPeek) actwind)->windowKind == ICONWINDKIND) {
- /* force invert redraw on MF switch */
-
- if (myEvent.modifiers & activeFlag) {
- if (keydp != ((WindowPeek) actwind)->refCon) {
- keydp = ((WindowPeek) actwind)->refCon;
- keywindow = keydp->emwindow;
- /* make emwindow key by default when new icon selected*/
- }
- iconwindow = actwind;
- }
-
- GetPort(&oldport);
- SetPort(twp->iconwindow);
- InvalRect(&((GrafPtr) twp->iconwindow)->portRect);
- SetPort(oldport);
- }
-
-
- if (myEvent.modifiers & activeFlag) {
- if (!mfpresent && darefnum) {
- /* manage menus for DA's */
- emedit(keydp, TRUE);
- DrawMenuBar();
- setscript(1L); /* pass E,I,N, U keys */
- }
- else if (menuredraw)
- DrawMenuBar();
- }
- else {
- if (!mfpresent && darefnum) {
- emedit(keydp, FALSE);
- DrawMenuBar();
- }
- }
- }
-
-
- updatewind()
- {
- GrafPtr oldport;
- WindowPtr updwind;
- struct winds * twp;
-
- updwind = myEvent.message;
- twp = ((WindowPeek) updwind)->refCon;
-
- GetPort(&oldport);
- if (((WindowPeek) updwind)->windowKind == EMWINDKIND) {
- getcontext(twp);
- (*twp->updatewind)();
- }
- #ifdef USETEXTWINDOWS
- else if (((WindowPeek) updwind)->windowKind == TEXTWINDKIND) {
- SetPort(twp->textwindow);
- BeginUpdate(updwind);
- EraseRect(&(*updwind->visRgn)->rgnBBox);
-
- if (twp->texthand) {
- TEUpdate(&(*updwind->visRgn)->rgnBBox, twp->texthand);
- UpdtControl(updwind, updwind->visRgn );
- }
- drawgrowicon(updwind);
-
- EndUpdate(updwind);
- }
- #endif
- #ifdef USEHELPWINDOW
- else if (((WindowPeek) updwind)->windowKind == HELPWINDKIND) {
- helpwhandle();
- }
- #endif
- else if (((WindowPeek) updwind)->windowKind == ICONWINDKIND) {
- /* redraw icon window--add title to picture */
- int titlewidth;
- short hpos;
- Rect destrect;
- struct winds * cons;
-
- SetPort(updwind);
- BeginUpdate(updwind);
-
- cons = ((WindowPeek) updwind)->refCon;
-
- destrect.top = 0;
- destrect.left = 0;
- destrect.bottom = 33;
- destrect.right = 46;
- /* dimensions of the telnet picture */
- DrawPicture(iconpict, &destrect);
- if (cons->iconhigh)
- /* show that data has arrived */
- InvertRect(&destrect);
-
- destrect.top = 33;
- destrect.bottom = 45;
- EraseRect(&destrect);
-
- if (cons->hhostname != NULL) {
- HLock(cons->hhostname);
-
- titlewidth = StringWidth(*cons->hhostname);
- titlewidth /= 2;
- hpos = 22 - titlewidth;
- if (hpos < 4)
- hpos = 4;
- MoveTo(hpos, 42);
-
- /* draw the host title */
- DrawString(*cons->hhostname);
- HUnlock(cons->hhostname);
- }
-
- if (cons->iconwindow == FrontWindow() && !mfbackground) {
- /* invert the title on the icon to show we're up top */
- InvertRect(&destrect);
- }
-
- EndUpdate(updwind);
- }
- else {
- /* we don't care, throw out the update event */
- SetPort(updwind);
- BeginUpdate(updwind);
- EndUpdate(updwind);
- }
- SetPort(oldport);
- }
-
- /* mousedown or keydown events on the event queue indicate user might
- want a break ... */
-
- user_intr()
- {
- EventRecord junkevt;
-
- if (EventAvail(keyDownMask | mDownMask, &junkevt))
- return(TRUE);
- else
- return(FALSE);
- }
-
-
- /* the tick counter has wrapped; reset all counters so timers will pop */
-
- user_tmwrap()
- {
- tickcursor = 0;
- tickstats = 0;
- tickserial = 0;
- mousedelay = 0;
- cursalarm = 0;
- }
-
- /* make the top window shrink down into an icon */
-
- shrinkwindow(twp)
- struct winds * twp;
- {
- GrafPtr oldport;
-
- twp->curson = FALSE;
- twp->icon_up = TRUE; /* lock the keyboard */
-
- ShowWindow(twp->iconwindow);
- HideWindow(twp->emwindow);
- #ifdef USETEXTWINDOWS
- HideWindow(twp->textwindow);
- #endif
-
- GetPort(&oldport);
- SetPort(twp->iconwindow);
- InvalRect(&((GrafPtr) twp->iconwindow)->portRect);
- SetPort(oldport);
-
- /* hidennr(); hide net not responding dialog */
- }
-
-
- /* make the top window expand from an icon to an emulator screen */
-
- expandwindow(twp)
- struct winds * twp;
- {
- GrafPtr oldport;
-
- GetPort(&oldport);
- SetPort(twp->iconwindow);
-
- #ifdef USETEXTWINDOWS
- if (twp->edit) {
- if (twp->textwindow != FrontWindow()) {
- /* don't select it unless necessary... */
- selectwindow(twp->emwindow);
- ShowWindow(twp->emwindow);
-
- selectwindow(twp->textwindow);
- ShowWindow(twp->textwindow);
- }
- }
- else {
- if (twp->emwindow != FrontWindow()) {
- if (!twp->hidetextwindow) {
- selectwindow(twp->textwindow);
- ShowWindow(twp->textwindow);
- }
- selectwindow(twp->emwindow);
- ShowWindow(twp->emwindow);
- }
- }
- #else
- if (twp->emwindow != FrontWindow()) {
- selectwindow(twp->emwindow);
- ShowWindow(twp->emwindow);
- }
- #endif
- HideWindow(twp->iconwindow);
-
- twp->icon_up = FALSE; /* restore keyboard */
- twp->iconhigh = FALSE;
-
- SetPort(oldport);
- }
-
-
- /* are we running under the multifinder? Set mode accordingly if not.
- This handles problem due to MF launches into background so drawing
- must be disabled--but with no MF present, bkrd = TRUE assumption locks out
- drawing forever under plain Finder which never offers "bring to MF
- foreground" event. We detect presence of MF by examining the Apple
- menu; if "Finder" is present in the Apple menu, we're under MF ... */
-
- chkmultifinder()
- {
- char * datap;
- int stop = 100;
-
- if (environs.systemVersion >= 0x0700)
- /* MultiFinder is all there is under System > 7.0 */
- return(TRUE);
-
- datap = (char *) (&(*menu[APPLEMENU])->menuData);
- datap += *datap + 1;
- /* skip the menu name */
-
- while (--stop) {
- /* more than 100 menu items in the apple menu indicates a problem--
- "you're not supposed to examine this record!" IM-V, I-364 */
- if (*datap == 0)
- /* we've run out of items to test, MF not present */
- break;
- if (EqualString(datap, "\PFinder", (Boolean) TRUE, (Boolean) TRUE))
- /* found item name "Finder"--we are under MultiFinder! */
- return(TRUE);
- datap += *datap + 5;
- /* skip this name & rest of item data and continue */
- }
- mfpresent = FALSE;
- mfbackground = FALSE;
- return(FALSE);
- }
-
-
- /* disallow drawing because we're waiting on an update event
- which implies there's a big white patch where the cursor
- might have been ON...
-
- or the emulator is disabled.
- */
-
- extern short appclosing;
-
- updatewait()
- {
- EventRecord junkevt;
-
- if (appclosing) {
- /* when the application is closing we might have a hang if
- we wait for an update... */
- return(FALSE);
- }
-
- if (emdp->emdisable || emdp->mfwait)
- return(TRUE);
-
- if (EventAvail(updateMask, &junkevt))
- /* no updates waiting, forget it */
- return(TRUE);
-
- return(FALSE);
- }
-
-
- /* disallow cursor drawing because we're waiting on an update event
- which implies there's a big white patch where the cursor
- might have been ON...
-
- or the emulator is disabled.
- */
-
- cupdatewait(twp)
- struct winds * twp;
- {
- EventRecord junkevt;
-
- if (appclosing) {
- /* when the application is closing we might have a hang if
- we wait for an update... */
- return(FALSE);
- }
-
- if (twp->emdisable || twp->mfwait)
- return(TRUE);
-
- if (EventAvail(updateMask, &junkevt))
- /* updates are waiting, forget it */
- return(TRUE);
-
- return(FALSE);
- }
-
-
- /* handle suspend/resume events */
-
- mfswitch(anevent)
- EventRecord * anevent;
- {
- Point thept;
- GrafPtr oldport;
- struct winds ** conp = conns;
- struct winds * conend = &conp[conncount];
- register struct winds * twp;
- struct winds * clicktwp;
- GrafPtr frontwind;
- GrafPtr movewind;
-
-
- if (! (anevent->message & 0x01000000L)) {
- return(FALSE);
- }
- /* go through window list & shunt aside all
- w/ mfbackground set ... */
-
- frontwind = FrontWindow();
- if (anevent->message & 1) {
- /* MultiFinder is putting us back on top, we handle Suspend/Resume
- we are "MultiFinder friendly" so we activate our window
- if we had a private scrap we'd coerce it
- */
- movewind = NULL;
- clicktwp = NULL;
- mfbackground = FALSE;
- setscript(1L);
-
- GetPort(&oldport);
-
- /* go through window list to expand autoshrink iconwindows */
- while (conp < conend) {
- twp = *conp++;
- if (twp == NULL || twp->emwindow == NULL)
- continue;
-
- if (twp->icon_up) {
- /* the icon window is up rather than the emulator window;
- move it around or bring it up; only bring up
- windows if not a move to facilitate placing icons */
-
- SetPort(twp->iconwindow);
- GetMouse(&thept);
- if (PtInRect(pass(thept), &((GrafPtr) twp->iconwindow)->portRect) ) {
- /* mouse down on iconwindow, drag */
- selectwindow(twp->iconwindow); /* added so windows other than top wind*/
- if (Button()) {
- LocalToGlobal(&thept);
- DragWindow(twp->iconwindow, pass(thept), &dragrect);
- mousedelay = cticks;
- movewind = twp->iconwindow;
- }
- clicktwp = twp;
- }
- }
- }
- /* go through the window list, expand autoshrink iconwindows and set drawing mode */
- conp = conns;
- while (conp < conend) {
- twp = *conp++;
- if (twp == NULL || twp->emwindow == NULL)
- continue;
-
- testds(twp);
-
- if (twp->icon_up) {
- if (movewind == NULL && twp->autoshrink) {
- /* if autoshrink on, expand UNLESS the user was moving
- an icon about */
-
- expandwindow(twp);
- /* make sure cursor won't be inverted until update event arrives
- on the queue; likewise make sure we have one (InvalRect will force redraw) */
- twp->mfwait = TRUE;
- InvalRect(&twp->dubshiftrect);
- }
- else
- InvalRect(&((GrafPtr) twp->iconwindow)->portRect);
- }
- else {
- /* make sure cursor won't be inverted until update event arrives
- on the queue; likewise make sure we have one (InvalRect will force redraw) */
- SetPort(twp->emwindow);
- twp->mfwait = TRUE;
- InvalRect(&twp->dubshiftrect);
- }
- }
- if (oldport)
- SetPort(oldport);
-
- if (clicktwp) {
- if (movewind == NULL) {
- /* if not a drag, make sure the one that was touched comes up on top */
- if (clicktwp->autoshrink) {
- expandwindow(clicktwp);
- }
- else {
- selectwindow(clicktwp->iconwindow);
- }
- }
- }
- else if (keywindow != NULL) {
- /* && keywindow == FrontWindow() */
- SetPort(keywindow);
- twp = ((WindowPeek) keywindow)->refCon;
-
- if (((WindowPeek) keywindow)->windowKind == EMWINDKIND) {
- bkrd_act = 0;
- }
- #ifdef USETEXTWINDOWS
- else if (((WindowPeek) keywindow)->windowKind == TEXTWINDKIND) {
- /* update the TE Scrap */
- twp = ((WindowPeek) keywindow)->refCon;
- TEActivate(twp->texthand);
- scraptote();
- twp->textscrapped = FALSE;
-
- ShowControl(twp->vBarHand);
- drawgrowicon(keywindow);
- }
- #endif
- #ifdef USEHELPWINDOW
- else if (((WindowPeek) keywindow)->windowKind == HELPWINDKIND) {
- /* forge an activate event */
- myEvent.message = keywindow;
- myEvent.what = activateEvt;
- myEvent.modifiers |= activeFlag);
- helpwhandle();
- }
- #endif
- }
- shownnr(); /* if "net not receiving" is up, show it */
- return(TRUE);
- }
- else {
- /* MF is putting us in the background */
- setscript(0L);
- hidennr(); /* hide nnr */
-
- emwdeactivate();
- mfbackground = TRUE;
- GetPort(&oldport);
- while (conp < conend) {
- twp = *conp++;
- if (twp == NULL || twp->emwindow == NULL)
- continue;
-
- if (twp->icon_up) {
- /* redraw it for mf friendliness' sake */
-
- SetPort(twp->iconwindow);
- InvalRect(&((GrafPtr) twp->iconwindow)->portRect);
- }
- else if (twp->autoshrink) {
- /* shrink the em window automatically */
- shrinkwindow(twp);
- }
- }
- #ifdef USETEXTWINDOWS
- if (((WindowPeek) keywindow)->windowKind == TEXTWINDKIND) {
- twp = ((WindowPeek) keywindow)->refCon;
- TEDeactivate(twp->texthand);
- HideControl(twp->vBarHand);
- if (twp->textscrapped) {
- tetoscrap(*TEScrHandle, TEScrLen);
- }
- drawgrowicon(keywindow);
- }
- #endif
- #ifdef USEHELPWINDOW
- if (((WindowPeek) keywindow)->windowKind == HELPWINDKIND) {
- /* forge an activate event */
- myEvent.message = keywindow;
- myEvent.what = activateEvt;
- myEvent.modifiers = 0; /* !activeFlag */
- helpwhandle();
- }
- #endif
- SetPort(oldport);
- return(FALSE);
- }
- }
-
-
- /* handle disk insertion event */
-
- diskevent(anevent)
- EventRecord * anevent;
- {
- if (myEvent.message & 0xFFFF0000) {
- /* top word is error code for mount: an error occurred so
- we should try to eject the disk, given that disk
- mounting is a long-winded synchronous process */
- Point where;
-
- where.h = 60;
- where.v = 60;
- DIBadMount(pass(where), myEvent.message);
- }
- }
-
-
- /* before we enter a modaldialog loop we need to check to make sure we're
- not in the background. */
-
-
- chkbackground()
- {
- EventRecord anevent;
-
- if (mfbackonly) {
- return(TRUE);
- }
- else if (mfbackground) {
- /* wait until we're brought into the foreground */
- while (TRUE) {
- SystemTask(); /* keep this if/until we use WaitNextEvent */
- if (GetNextEvent(app4Mask, &anevent)) {
- /* wait for a mf switch in */
- if (mfswitch(&anevent))
- /* we've been switched in and can continue */
- break;
- }
- else {
- bkrd_service();
- continue; /* KS */
- }
- }
- }
- return(FALSE);
- }
-
-
- /* all event loops in the application call defaultevent() when the receive
- an event for which they have no handler */
-
- defaultevent(anevent)
- EventRecord * anevent;
- {
- switch (anevent->what) {
- case diskEvt: {
- diskevent(anevent);
- break;
- }
- case app4Evt: {
- mfswitch(anevent);
- break;
- }
- }
- }
-
- /* a bottleneck call... */
-
- selectwindow(thewind)
- WindowPtr thewind;
- {
- if (thewind == FrontWindow())
- /* this is already the front window */
- return();
-
- emwdeactivate();
- /* gotta do this first since apple WM delivers activate event FIRST??!! */
- SelectWindow(thewind);
- }
-
- /* turn off the top window and turn on flags to indicate we're in the
- background now.
-
- NB there may be problems here with cursor turds if update
- event following activate received following deactivate
- */
-
-
- emwdeactivate()
- {
- GrafPtr oldport;
-
- ++bkrd_act;
- SetCursor(&arrow);
-
- if (keywindow == NULL || emwindow == NULL)
- return;
-
- GetPort(&oldport);
-
- if (keydp->emwindow == FrontWindow()) {
- SetPort(keydp->emwindow);
- if (keydp->curson) {
- InvertRect(&keydp->cursrect);
- keydp->curson = FALSE;
- } /* must the cursor be deactivated ? */
-
- if (trackon) {
- InvertRect(&mouserect);
- trackon = FALSE;
- }
- }
- #ifdef USETEXTWINDOWS
- if (keydp->textwindow == FrontWindow()) {
- SetPort(keydp->textwindow);
- TEDeactivate(keydp->texthand);
- HideControl(keydp->vBarHand);
- if (keydp->textscrapped) {
- tetoscrap(*TEScrHandle, TEScrLen);
- keydp->textscrapped = FALSE;
- }
- drawgrowicon(keydp->textwindow);
- }
- #endif
- SetPort(oldport);
- }
-
-
- /* The following routines deal with converting the screen image to ASCII
- text without trailing spaces & CRs appended and saving/printing
- the resulting text */
-
- /* same as ZeroScrap */
-
- scrapzero()
- {
- SetHandleSize(ScrapHandle, 0L); /* set handle size to zero */
- *ScrapSize = 0; /* set length = type + len + text */
- }
-
-
- /* add text to the scrap:
-
- scrap format: long type
- text data:
- long length
- char []
- */
-
-
- puttextscrap(textp, length)
- char * textp;
- long length;
- {
- Handle scraptemp;
- long oldlength;
- long offset;
- int result;
-
- LoadScrap(); /* guarantee scrap in memory */
-
- scraptemp = NewHandle(0L);
-
- oldlength = GetScrap(scraptemp, 'TEXT', &offset);
- if (oldlength < 0
- && oldlength != noTypeErr
- && oldlength != noScrapErr
- ) {
- /* a system error occurred */
- DisposHandle(scraptemp);
- return(-1);
- }
- else if (oldlength > 0) {
- /* text is present in scrap, we want to append */
- ZeroScrap(); /* IM 1-459 multiple appends don't work so kill old scrap */
-
- if (PtrAndHand(textp, scraptemp, length)) {
- DisposHandle(scraptemp);
- return(-1);
- }
- length += oldlength;
-
- MoveHHi(scraptemp);
- HLock(scraptemp);
- result = PutScrap(length, 'TEXT', *scraptemp);
- HUnlock(scraptemp);
- }
- else {
- /* no TEXT in scrap */
- result = PutScrap(length, 'TEXT', textp);
- }
- DisposHandle(scraptemp);
- if (result)
- return(-1);
- else
- return(0);
- }
-
-
- long gettextscrap(pthep)
- long ** pthep;
- {
- long length;
- long offset;
-
- LoadScrap(); /* guarantee scrap in memory */
-
- if (scraptemp == (Handle) NULL) {
- scraptemp = NewHandle(0L);
- }
- else {
- releasescrap();
- scraptemp = NewHandle(0L);
- }
-
- length = GetScrap(scraptemp, 'TEXT', &offset);
- if (length <= 0)
- return(0);
-
- HLock(scraptemp);
- *pthep = (long *)(* scraptemp); /* set data ptr */
- return(length); /* return the length */
- }
-
- releasescrap()
- {
- if (scraptemp != NULL) {
- HUnlock(scraptemp);
- DisposHandle(scraptemp);
- scraptemp = NULL;
- }
- }
-
-
- /* copies the selection or full screen if no selection;
- returns length, 0 on error */
-
- getselection(copyp)
- char * * copyp;
- {
- int length;
- char * mapp;
-
- if (!memtest((long) (emdp->screensize + emdp->linelength + 2), ©err[0])) {
- /* not enough memory for operation */
- *copyp = NULL;
- return(0);
- }
- /* TODO should be from window struct */
- if (emdp->ibm_mode)
- mapp = scr_map;
- else
- mapp = &emdp->charr[0];
-
- *copyp = NewPtr((long) (emdp->screensize + emdp->linelength + 2));
- if (emdp->selrectset) {
- /* copy the user's selection rectangle */
- int selstart;
- int sellen;
-
- selstart = emdp->selystart * emdp->linelength + emdp->selxstart;
- sellen = emdp->selyend * emdp->linelength + emdp->selxend - selstart;
- if (sellen < 0) {
- /* something very wrong here! */
- DisposPtr(*copyp);
- *copyp = NULL;
- return(0);
- }
- else if (sellen == 0) {
- /* a null selection exists */
- selstart = 0;
- sellen = emdp->screensize;
- }
- length = screencopy(mapp, selstart, *copyp, sellen, FALSE);
- }
- else {
- /* copy the whole screen if no selection */
- length = screencopy(mapp, 0, *copyp, emdp->screensize, FALSE);
- }
- if (length == 0) {
- DisposPtr(*copyp);
- *copyp = NULL;
- }
- return(length);
- }
-
-
- /* if logging is on, append a line to the appropriate outputs,
- skipping spaces and adding a CR */
-
- /* todo MULTIWIND puttextscrap becomes textwappend */
-
- saveline(copyp, len)
- unsigned char * copyp;
- int len;
- {
- Ptr blankp;
- char acr;
-
- #ifndef USETEXTWINDOWS
- if (mfpresent)
- /* make sure mf updates all client's scrap info */
- SystemEdit(EDCOPY - 1);
-
- if (!scrapzeroed) {
- /* zero the scrap the first time through */
- scrapzeroed = TRUE;
- ZeroScrap();
- }
- #endif
- if (!emdp->logsession && !emdp->filesession)
- return;
-
- #ifdef IBMMODENOSCROLL
- /* if this is enabled no session connect info scrolling off the top
- will be saved, which is probably not what we want... */
- if (emdp->ibm_keymode)
- /* logging in ibm_keymode is done when PF key pressed */
- return;
- #endif
-
- blankp = copyp + len;
- while (--blankp >= copyp) {
- /* skip blanks */
- if (*blankp != ' ')
- break;
- }
- if (blankp >= copyp) {
- /* we have non-blanks to copy */
- len = blankp - copyp + 1;
- if (emdp->logsession) {
- textwappend(copyp, (long) len);
- }
- if (emdp->filesession) {
- logappend(copyp, (long) len);
- }
- }
- /* add a carriage return */
- acr = CR;
- len = 1;
- if (emdp->logsession) {
- textwappend(&acr, (long) len);
- }
- if (emdp->filesession) {
- logappend(&acr, (long) len);
- }
- }
-
-
- /* if logging is on, append the screen to the textwindow and/or file */
-
- savescreen()
- {
- Ptr copyp;
- long len;
-
- #ifndef USETEXTWINDOWS
- if (mfpresent)
- /* make sure mf updates all client's scrap info */
- SystemEdit(EDCOPY - 1);
-
- if (!scrapzeroed) {
- /* zero the scrap the first time through */
- scrapzeroed = TRUE;
- ZeroScrap();
- }
- #endif
- if (emdp->logsession || emdp->filesession) {
- if ((len = getscreen(©p)) == 0) {
- DisposPtr(copyp);
- return;
- }
- if (emdp->logsession) {
- if (memtest(len, ©err[0])) {
- /* not enough memory for operation */
- textwappend(copyp, len);
- }
- }
- if (emdp->filesession)
- /* append screen to log file */
- logappend(copyp, len);
-
- DisposPtr(copyp);
- }
- }
-
-
-
- /* copies the full screen; returns length, 0 on error */
-
- getscreen(copyp)
- char * * copyp;
- {
- int length;
- char * mapp;
-
- if (!memtest((long) (emdp->screensize + emdp->linelength + 2), ©err[0])) {
- /* not enough memory for operation */
- return(0);
- }
- /* TODO should be from window struct */
- if (emdp->ibm_mode)
- mapp = scr_map;
- else
- mapp = &emdp->charr[0];
-
- *copyp = NewPtr((long) (emdp->screensize + emdp->linelength + 2));
-
- /* copy the whole screen */
- length = screencopy(mapp, 0, *copyp, emdp->screensize);
- return(length);
- }
-
-
- /* saves/appends text */
-
- savetext(action)
- unsigned char action;
- {
- char * copyp; /* ptr to screen copy area */
- long len; /* len of the screen copy */
- long fpos; /* file pointer */
- /* Standard File dialog handles */
- Handle hsfreplace; /* -3996 DITL */
- Ptr sfreplace;
- Handle hsfappend; /* 128 DITL with "Append" rather than "Replace" */
-
-
- if (emdp->reply.fName[0] == 0) {
- /* if no file name has been specified, do a save as... */
- if (action == RF_SAVE)
- action = RF_SAVEAS;
- if (action == RF_APPEND)
- action = RF_APPENDTO;
- }
- /* set the text pointer/length */
- if (emdp->edit) {
- /* edit window is up */
- HLock((*emdp->texthand)->hText);
- copyp = *(*emdp->texthand)->hText;
-
- if ((*emdp->texthand)->selStart != (*emdp->texthand)->selEnd) {
- /* save the selection rather than the whole thing */
- copyp += (*emdp->texthand)->selStart;
- len = ((*emdp->texthand)->selEnd - (*emdp->texthand)->selStart);
- }
- else
- len = (*emdp->texthand)->teLength;
- }
- else {
- if ((len = getselection(©p)) == 0) {
- return;
- }
- }
- if (action == RF_SAVE || action == RF_APPEND) {
- /* save or append to current file */
- if (FSOpen(&emdp->reply.fName, emdp->reply.vRefNum, &emdp->savefid)) {
- error(fileopenerr);
- return;
- }
- SetFPos(emdp->savefid, action == RF_APPEND ? fsFromLEOF : fsFromStart, (long) 0);
- /* position file ptr at EOF if append mode */
-
- if (FSWrite(emdp->savefid, &len, copyp))
- error(filewriteerr);
-
- GetFPos(emdp->savefid, &fpos);
- SetEOF(emdp->savefid, fpos);
- FSClose(emdp->savefid);
- FlushVol((StringPtr) NULL, 0);
- emdp->savefid = 0;
- }
- else if (action == RF_SAVEAS || action == RF_APPENDTO) {
- /* save as... or append to... do a dialog to get the filename/folder */
- Point here;
- char tbuf[256];
- char namebuf[256];
-
- here.v = 60;
- here.h = 100;
- centerpoint(&here);
-
- if (action == RF_APPENDTO) {
- sprintf(tbuf, "Append %s to:", emdp->seltype);
-
- /* switch Standard File dialog handles */
- hsfreplace = GetResource('DITL', -3996); /* -3996 DITL */
- if (hsfreplace) {
- HLock(hsfreplace);
- HNoPurge(hsfreplace);
- sfreplace = *hsfreplace;
-
- hsfappend = GetResource('DITL', 128); /* 128 DITL with "Append" rather than "Replace" */
- HLock(hsfappend);
- HNoPurge(hsfappend);
- if (hsfappend)
- *hsfreplace = *hsfappend; /* point to the other DITL */
- }
- }
- else {
- sprintf(tbuf, "Save %s as:", emdp->seltype);
- }
- ctop(tbuf);
-
- #ifdef USELOGNAME
- /* automatic logging is assisted by a default name of "sessionname.log" */
- GetWTitle(emdp->emwindow, &namebuf[0]);
- ptoc(&namebuf[0]);
- strcat(&namebuf[0], ".log");
- ctop(&namebuf[0]);
-
- SFPutFile(pass(here), tbuf, &namebuf[0], (ProcPtr) NULL, &emdp->reply);
- #else
- SFPutFile(pass(here), tbuf, &untitled[0], (ProcPtr) NULL, &emdp->reply);
- #endif
-
- if (action == RF_APPENDTO) {
- /* switch back Standard File dialog handles */
-
- if (hsfreplace) {
- *hsfreplace = sfreplace;
- HUnlock(hsfreplace);
- HPurge(hsfreplace);
- ReleaseResource(hsfreplace);
- if (hsfappend) {
- HUnlock(hsfreplace);
- HPurge(hsfreplace);
- ReleaseResource(hsfappend);
- }
- }
- }
- if (emdp->reply.good) {
- if (FSOpen(&emdp->reply.fName, emdp->reply.vRefNum, &emdp->savefid)) {
- /* create new file if necessary */
- if (Create(&emdp->reply.fName, emdp->reply.vRefNum, '????', 'TEXT')) {
- error(filecreateerr);
- return;
- }
- if (FSOpen(&emdp->reply.fName, emdp->reply.vRefNum, &emdp->savefid)) {
- error(fileopenerr);
- return;
- }
- }
- filetitles(emdp);
- EnableItem(menu[FILEMENU], SAVESCREEN);
- EnableItem(menu[FILEMENU], APPENDSCREEN);
-
- if (action == RF_APPENDTO)
- /* position file ptr at EOF */
- SetFPos(emdp->savefid, fsFromLEOF, (long) 0);
- else
- SetFPos(emdp->savefid, fsFromStart, (long) 0);
- if (FSWrite(emdp->savefid, &len, copyp))
- error(filewriteerr);
- GetFPos(emdp->savefid, &fpos);
- SetEOF(emdp->savefid, fpos);
-
-
- FSClose(emdp->savefid);
- FlushVol((StringPtr) NULL, 0);
- emdp->savefid = 0;
- }
- else {
- /* make sure the Pascal-string reply name is NULL, not "Untitled" */
- emdp->reply.fName[0] = 0;
- }
- }
- /* free the text pointer */
- if (emdp->edit)
- HUnlock((*emdp->texthand)->hText);
- else
- DisposPtr(copyp);
- }
-
-
- /* open a log file */
-
- logopen()
- {
- Point here;
- char namebuf[256];
- /* Standard File dialog handles */
- Handle hsfreplace; /* -3996 DITL */
- Ptr sfreplace;
- Handle hsfappend; /* 128 DITL with "Append" rather than "Replace" */
-
- /* set the text pointer/length */
- /* save as... or append to... do a dialog to get the filename/folder */
- here.v = 60;
- here.h = 100;
- centerpoint(&here);
-
- if (emdp->logreply.fName[0] == 0) {
- /* automatic logging is assisted by a default name of "sessionname.log" */
- GetWTitle(emdp->emwindow, &emdp->logreply.fName[0]);
- ptoc(&emdp->logreply.fName[0]);
- strcat(&emdp->logreply.fName[0], ".log");
- ctop(&emdp->logreply.fName[0]);
- }
-
- /* switch Standard File dialog handles */
- hsfreplace = GetResource('DITL', -3996); /* -3996 DITL */
- if (hsfreplace) {
- HLock(hsfreplace);
- HNoPurge(hsfreplace);
- sfreplace = *hsfreplace;
-
- hsfappend = GetResource('DITL', 128); /* 128 DITL with "Append" rather than "Replace" */
- HLock(hsfappend);
- HNoPurge(hsfappend);
- if (hsfappend)
- *hsfreplace = *hsfappend; /* point to the other DITL */
- }
-
- SFPutFile(pass(here), "\PLog session in file", &emdp->logreply.fName[0], (ProcPtr) NULL, &emdp->logreply);
-
- /* switch back Standard File dialog handles */
- if (hsfreplace) {
- *hsfreplace = sfreplace;
- HUnlock(hsfreplace);
- HPurge(hsfreplace);
- ReleaseResource(hsfreplace);
- if (hsfappend) {
- HUnlock(hsfreplace);
- HPurge(hsfreplace);
- ReleaseResource(hsfappend);
- }
- }
- if (emdp->logreply.good) {
- if (emdp->logfid) {
- /* if a log file has been opened, close it... */
- logclose();
- }
- if (FSOpen(&emdp->logreply.fName, emdp->logreply.vRefNum, &emdp->logfid)) {
- /* create new file if necessary */
- if (Create(&emdp->logreply.fName, emdp->logreply.vRefNum, '????', 'TEXT')) {
- error(filecreateerr);
- return;
- }
- if (FSOpen(&emdp->logreply.fName, emdp->logreply.vRefNum, &emdp->logfid)) {
- error(fileopenerr);
- return;
- }
- }
- filetitles(emdp);
-
- /* position file ptr at EOF */
- SetFPos(emdp->logfid, fsFromLEOF, (long) 0);
- return(TRUE);
- }
- return(FALSE);
- }
-
-
- /* close the log file */
-
- logclose()
- {
- if (emdp->logfid) {
- FSClose(emdp->logfid);
- FlushVol((StringPtr) NULL, 0);
- emdp->logfid = 0;
- }
- }
-
- /* log text in the selected log file */
-
- logappend(copyp, len)
- char * copyp; /* ptr to screen copy area */
- long len; /* len of the screen copy */
- {
- long fpos; /* file pointer */
-
- if (emdp->logfid == 0) {
- if (!logopen()) {
- menufile(FILESESSION); /* toggle logging off if user rejects */
- return;
- }
- }
- if (FSWrite(emdp->logfid, &len, copyp))
- error(filewriteerr);
-
- GetFPos(emdp->logfid, &fpos);
- SetEOF(emdp->logfid, fpos);
- }
-
-
- /* print a screen or the .edit window using the Streaming Text routines,
- which are no longer supported by Apple */
-
- printtext(type)
- {
- char * copyp; /* ptr to screen copy area */
- long len; /* len of the screen copy */
- unsigned char * thep;
- char * stakep;
- char * endp;
- int topmarg; /* 6 lines for top margin */
- char * leftmarg = " "; /* 11 spaces for 1.25" left marg */
- int linecount;
-
- if (emdp->edit) {
- /* edit window is up, print it */
- textwwrap(emdp);
- HLock((*emdp->texthand)->hText);
- copyp = *(*emdp->texthand)->hText;
- len = (*emdp->texthand)->teLength;
- }
- else {
- if ((len = getselection(©p)) == 0)
- goto PRINTABORT1;
- }
-
- thep = copyp;
- endp = copyp + len;
-
- /* use the Print Mgr streaming text routines */
- PrDrvrOpen();
- if (PrError()) {
- error("Can't open printer driver");
- goto PRINTABORT1;
- }
- PrCtlCall(iPrDevCtl, (long) lPrDocOpen, (long) 0, (long) 0);
- if (PrError()) {
- error("Can't open printer document");
- goto PRINTABORT2;
- }
- while (TRUE) {
- PrCtlCall(iPrDevCtl, (long) lPrPageOpen, (long) 0, (long) 0);
- if (PrError()) {
- error("Can't open printer page");
- goto PRINTABORT3;
- }
- for (topmarg = 6; --topmarg; ) {
- /* leave margin at top of page */
- PrCtlCall(iPrDevCtl, (long) lPrLFSixth, (long) 0, (long) 0);
- }
- stakep = thep;
- for (linecount = 0; thep < endp && linecount < 56; ) {
- /* print line by line */
- if (*thep++ == CR) {
- /* print the line and do CRLF */
- PrCtlCall(iPrIOCtl, leftmarg, (long) 11, (long) 0);
- PrCtlCall(iPrIOCtl, stakep, (long) (thep - stakep), (long) 0);
- PrCtlCall(iPrDevCtl, (long) lPrLFSixth, (long) 0, (long) 0);
- stakep = thep;
- linecount++;
- }
- }
- if (thep >= endp)
- break;
- PrCtlCall(iPrDevCtl, (long) lPrPageClose, (long) 0, (long) 0);
- }
- if (thep != stakep)
- /* print the last line */
- PrCtlCall(iPrIOCtl, stakep, (long) (thep - stakep), (long) 0);
- PrCtlCall(iPrDevCtl, (long) lPrPageClose, (long) 0, (long) 0);
-
- PRINTABORT3:
- PrCtlCall(iPrDevCtl, (long) lPrDocClose, (long) 0, (long) 0);
-
- PRINTABORT2:
- PrDrvrClose();
-
- PRINTABORT1:
- if (emdp->edit) {
- textwunwrap(emdp);
- HUnlock((*emdp->texthand)->hText);
- }
- else {
- if (copyp != NULL)
- DisposPtr(copyp);
- }
- }
-
- short tabthreshold; /* useless unless user can set it somehow... */
-
- /* copy screen from scr_map format into a buffer, returning count copied
- target buffer must have (emdp->screensize + emdp->linelength) bytes minimum
- */
-
- screencopy(screenp, offset, destarr, count)
- unsigned char * screenp; /* points into scr_map to read from */
- int offset; /* offset into map */
- unsigned char * destarr; /* points to dest to write into */
- int count; /* scrp + count -> last char to copy, exclusive */
- {
- register unsigned char * srcp = screenp + offset;
- register unsigned char * destp = destarr;
- register unsigned char * endp = srcp + count; /* stake out the excluded end */
- register unsigned char * linep; /* temp */
- unsigned char * lineend; /* really beginning of next line */
- register unsigned char thechar;
- register int charcount; /* # of good chars left in line */
- int firsttime = TRUE; /* skip CR first time through loop */
- int spacesseen; /* copytable--spaces have been elided */
- int newrow; /* copytable--no tab for leading spaces */
- short invisible = FALSE; /* default is no invisibles for ASCII */
-
- /* set up the charcount var for entry into the loop */
- lineend = screenp + (((offset / emdp->linelength)) * emdp->linelength);
- /* set up lineend, which will point to beginning of next line */
- charcount = 0;
- if (emdp->copytable) {
- /* adjust start */
- srcp -= emdp->selxstart;
- }
-
- if (emdp->ibm_mode) {
- /* hey, it's probably a good idea not to record invisible stuff! */
- invisible = (((ibm_attr(srcp)) & DSPD) == INVIS);
- /* if we're in an invisible field, note this fact */
- }
- while (TRUE) {
- if (srcp >= endp)
- /* quit when we've done the work */
- break;
-
- if (--charcount <= 0) {
- /* it's either the end of the line or an initialization */
- if (!firsttime) {
- /* put a CR after initialization */
- *destp++ = CR; /* insert a CR for line end */
- srcp = lineend; /* set srcp forward */
- if (srcp >= endp)
- /* quit when we've done the work */
- break;
- }
-
- spacesseen = 0;
- newrow = TRUE;
- if (emdp->copytable
- && (emdp->selxend == 0 || emdp->selxstart < emdp->selxend)) {
-
- /* only copy within two x positions of selection start and end */
- /* if range is negative, we do a regular copy */
-
- srcp += emdp->selxstart;
- if (srcp >= endp)
- /* quit when we've done the work */
- break;
-
- lineend += emdp->linelength;
- if (emdp->selxend == 0) {
- /* selxend is NOT included in the range, so it's 0 when the
- end of line is selected! */
- charcount = emdp->linelength - emdp->selxstart;
- linep = lineend;
- }
- else {
- charcount = emdp->selxend - emdp->selxstart;
- linep = lineend - emdp->linelength + emdp->selxend;
- }
- }
- else {
- lineend += emdp->linelength;
- linep = lineend;
- if (firsttime)
- charcount = emdp->linelength - emdp->selxstart;
- else
- charcount = emdp->linelength;
- }
- for (--linep; charcount; --linep) {
- /* go back up to beginning of line to elide empty space */
- thechar = *linep;
- if ( thechar == SPACE
- || thechar == IBMNULL
- || thechar < ATTR) {
-
- charcount--;
- continue;
- }
- else
- break;
- }
-
- if (firsttime) {
- /* clear initialization flag */
- firsttime = FALSE;
- }
- if (charcount <= 0) {
- /* nothing on the whole line, skip it */
- continue;
- }
- if (emdp->ibm_mode) {
- /* check to find out what the current attribute is */
- invisible = (((ibm_attr(srcp)) & DSPD) == INVIS);
- /* if we're in an invisible field, note this fact */
- }
- }
- /* copy the char from srcp to destp depending on the mode... */
- thechar = *srcp++;
- if (emdp->copytable) {
- if ( thechar == SPACE
- || thechar == IBMNULL
- )
- {
- spacesseen++;
- continue;
- }
- if (emdp->ibm_mode) {
- if (thechar < ATTR) {
- /* for ibm emulators hide invisible */
- invisible = ((thechar & DSPD) == INVIS);
- spacesseen++;
- continue;
- }
- else if (invisible) {
- spacesseen++;
- continue;
- }
- }
- if (spacesseen) {
- /* TODO copy table threshold? */
- #ifdef DONEWROW
- /* automatically suppresses leading space -> TAB, not really
- a good idea */
- if (newrow)
- newrow = FALSE;
- else
- #else
- if (spacesseen < tabthreshold) {
- /* if we've seen fewer spaces than the threshold,
- put them out rather than a tab */
- spacesseen++; /* setup for predecrement */
- while (--spacesseen) {
- *destp++ = SPACE;
- }
- continue;
- }
- #endif
- *destp++ = TAB; /* stick in a TAB */
- spacesseen = 0;
- }
- *destp++ = thechar;
- newrow = FALSE; /* only skip leading blanks on new row */
- }
- else {
- /* ordinary, rather than copy table mode */
- if (emdp->ibm_mode) {
- if (thechar < ATTR) {
- *destp++ = SPACE;
- invisible = ((thechar & DSPD) == INVIS);
- }
- else if ((thechar == IBMNULL) || invisible) {
- /* use space for nulls and invisible chars */
- *destp++ = SPACE;
- }
- else
- *destp++ = thechar;
- }
- else
- *destp++ = thechar;
- }
- }
- *destp = '\000'; /* put a null at the end for C-safety's sake */
- return(destp - destarr); /* return length */
- }
-
- #ifdef MYSCRAP
-
- tetoscrap(fromp, size)
- char * fromp;
- short size;
- {
- if (memtest( (long) size, "to copy TextEdit Scrap to Clipboard")) {
- if ( ! ZeroScrap())
- if ( ! PutScrap((long) size, 'TEXT', fromp) )
- if (! UnloadScrap())
- return(size);
- }
- }
-
- scraptote()
- {
- long size;
- long offset;
-
- if ( (size = GetScrap( (Handle) NULL, 'TEXT', &offset) ) > 0 ) {
- if (memtest((long) size * 2, "to copy Clipboard to TextEdit Scrap")) {
- /* * 2 for extra copy GetS makes */
- SetHandleSize(TEScrHandle, 0L);
- size = GetScrap(TEScrHandle, 'TEXT', &offset);
- if (size >= 0) {
- TEScrLen = size;
- return(size);
- }
- }
- }
- else if (size == noTypeErr)
- return(0L);
- }
-
- #else
-
- tetoscrap(fromp, size)
- char * fromp;
- short size;
- {
- if (memtest( (long) size, "to copy TextEdit Scrap to Clipboard")) {
- if ( ! ZeroScrap())
- if (! TEToScrap())
- return(size);
- }
- return(0);
- }
-
-
- scraptote()
- {
- long size;
- long offset;
-
- if ( (size = GetScrap( (Handle) NULL, 'TEXT', &offset) ) > 0 ) {
- if (memtest((long) size * 2, "to copy Clipboard to TextEdit Scrap")) {
- /* * 2 for extra copy GetS makes */
- if (!TEFromScrap()) {
- return(size);
- }
- }
- }
- return(0);
- }
-
- #endif
-
-
-
-
- /* clip DrawGrowIcon so the unused horizontal scrollbar zone isn't drawn */
-
- drawgrowicon(updwind)
- WindowPtr updwind;
- {
- GrafPtr oport;
- RgnHandle oldclip;
- Rect iconrect;
-
- /* clip the drawing rgn so only the Grow Icon & vertical
- scrollbar are drawn */
- GetPort(&oport);
- SetPort(updwind);
-
- oldclip = NewRgn();
- GetClip(oldclip);
-
- iconrect.bottom = updwind->portRect.bottom;
- iconrect.right = updwind->portRect.right;
- iconrect.top = updwind->portRect.top;
- iconrect.left = iconrect.right - 15;
-
- ClipRect(&iconrect);
- DrawGrowIcon(updwind);
-
- SetClip(oldclip);
- DisposeRgn(oldclip);
-
- SetPort(oport);
- }
-
-
- #ifdef DOQDPRINT
- /* print using QuickDraw */
-
- #define INRANGE(thecount) ((thecount >= (*hprec)->prJob.iFstPage) \
- && (thecount <= (*hprec)->prJob.iLstPage))
- /* this provides a range test to check whether we should draw... */
-
- THPrint hprec;
-
- QDprinttext(type, dodialog)
- int type;
- int dodialog;
- {
- char * copyp; /* ptr to screen copy area */
- long len; /* len of the screen copy */
- unsigned char * thep;
- char * stakep;
- char * endp;
- int voffset; /* 6 lines for top margin */
- int hoffset; /* offset for text printing */
- int bottommarg;
- int pagecount;
- int linecount;
- int charcount;
- char pageno[255]; /* page number string for printing */
- int pageinrange; /* flag to indicate page is in range */
- int copies; /* number of copies */
-
- TPPrPort pport;
- TPrStatus pstat;
- GrafPtr oport;
- unsigned long omodflg;
- unsigned long oclrflg;
- int ofontsize;
- int olineheight;
- int ofont;
- int ohighfont;
- int ofontwidth;
- int ohoffset;
- int ovoffset;
- int ofontdescent;
- int ocolor;
- int device;
-
- GetPort(&oport);
-
- if (!memtest((long) 5000, "to print")) {
- /* WARNING: 2836 was observed, 5000 may not be worst case */
- return(0);
- }
-
- if (hprec == NULL) {
- hprec = NewHandle((long) sizeof(TPrint));
- PrintDefault(hprec);
- if (hprec == NULL)
- return(-1);
- }
-
- /* use the Print Mgr and QuickDraw to image the text */
- PrOpen();
- if (PrError()) {
- error("Can't open printer driver");
- goto PRQDABORT1;
- }
- if (dodialog) {
- emwdeactivate();
-
- if (!PrJobDialog(hprec))
- return(0);
-
- }
- copies = (*hprec)->prJob.iCopies;
- device = (*hprec)->prStl.wDev >> 8; /* high byte contains device type */
-
- if (type == RF_PRINTSCREEN) {
- if ((len = getselection(©p)) == 0)
- goto PRQDABORT2;
- }
- else if (type == RF_PRINTTEXT) {
- HLock((*emdp->texthand)->hText);
- copyp = *(*emdp->texthand)->hText;
- len = (*emdp->texthand)->teLength;
- }
- else if (type == RF_PRINTSCRAP) {
- /* print the clipboard */
- if (! (len = gettextscrap(©p)))
- goto PRQDABORT2;
- }
-
- pport = PrOpenDoc(hprec, (long) 0, (long) 0);
- if (PrError()) {
- error("Can't open printer document");
- goto PRQDABORT2;
- }
-
- omodflg = modflg;
- oclrflg = clrflg;
- ofontsize = emdp->fontsize;
- olineheight = emdp->lineheight;
-
- ofont = emdp->normfont;
- ohighfont = emdp->highfont;
- ofontwidth = fontwidth;
- ohoffset = emdp->hoffset;
- ovoffset = emdp->voffset;
- ofontdescent = emdp->fontdescent;
- ocolor = emdp->color;
-
- while (copies--) {
- /* and now we do the drawing */
- charcount = 0;
- pagecount = 0;
- thep = copyp;
- endp = copyp + len;
-
- if (type == RF_PRINTTEXT) {
- int *lStart = &(*emdp->texthand)->lineStarts[0];
-
- while (TRUE) {
- /* go through a number of pages */
- pagecount++;
-
- if ((pageinrange = INRANGE(pagecount))) {
- PrOpenPage(pport, (long) 0);
- }
- if (PrError()) {
- error("Can't open printer page");
- goto PRQDABORT3;
- }
-
- /* interpret size and font literally for .edit window,
- unless we're using a Laser Writer */
-
- TextFont(emdp->normfont);
- TextSize(emdp->fontsize);
- hoffset = fontwidth * 12;
- if (emdp->fontsize == 12)
- hoffset = fontwidth * 8;
- else if (emdp->fontsize == 16)
- hoffset = 2;
-
- if (device == bDevLaser) {
- /* LaserWriter will use 36 pt (actually 50 pt) font
- so we can enhance print quality */
- if (courierprint) {
- TextFont(monaco);
- TextSize(9);
- emdp->lineheight = 12;
- hoffset = 50;
- }
- else {
- TextSize(9);
- emdp->lineheight = 12;
- hoffset = 50;
- }
- }
- voffset = 48;
- bottommarg = (*hprec)->prInfo.rPage.bottom - (3 * emdp->lineheight);
-
- stakep = thep;
- for (linecount = 0; thep < endp; thep++, charcount++) {
- /* print line by line leaving ~ an inch margin at the bottom*/
- if (charcount >= *lStart) {
- /* we're at or past a line break, position cursor & draw line */
- if (pageinrange) {
- MoveTo(hoffset, voffset);
- DrawText(stakep, 0, (thep - stakep));
- }
- stakep = thep;
- linecount++;
- lStart++;
-
- voffset += emdp->lineheight;
- if (voffset > bottommarg) {
- /* at bottom of page */
- if (pageinrange) {
- voffset += 2 * emdp->lineheight;
- sprintf(pageno, "%5d", pagecount);
- MoveTo( ((*hprec)->prInfo.rPage.right
- - (*hprec)->prInfo.rPage.left) / 2 - 30,
- voffset);
- DrawText(pageno, 0, strlen(pageno));
- }
- break;
- }
- }
- }
- if (thep >= endp) {
- /* we've gone through the whole text */
- if (thep != stakep) {
- /* print the last line */
- if (pageinrange) {
- MoveTo(hoffset, voffset);
- DrawText(stakep, 0, (thep - stakep));
- }
- }
- if (pageinrange) {
- /* print last page # */
- if (pageinrange) {
- voffset = bottommarg;
- voffset += 2 * emdp->lineheight;
- sprintf(pageno, "%5d", pagecount);
- MoveTo( ((*hprec)->prInfo.rPage.right
- - (*hprec)->prInfo.rPage.left) / 2 - 30,
- voffset);
- DrawText(pageno, 0, strlen(pageno));
- }
- PrClosePage(pport);
- }
- break; /* print next copy */
- }
- if (pageinrange) {
- PrClosePage(pport);
- }
- }
- }
- else {
- /* print the image on the emulator screen */
- PrOpenPage(pport, (long) 0);
- if (PrError()) {
- error("Can't open printer page");
- goto PRQDABORT3;
- }
-
- /* emdp->color = TRUE; color on to get inverse text */
- TextFont(emdp->normfont);
- TextSize(emdp->fontsize);
- emdp->hoffset = fontwidth * 12;
- if (emdp->fontsize == 12)
- emdp->hoffset = fontwidth * 8;
- else if (emdp->fontsize == 16)
- emdp->hoffset = 2;
-
- emdp->voffset = 72; /* leave an inch at the top */
-
- #ifdef DUPESERIAL
- /* we might as well let the user get the size they're using... */
- if (device == bDevCItoh) {
- /* will use 16 point font on ImageWriter? */
- TextSize(16);
- emdp->fontsize = 16;
- emdp->lineheight = 12;
- fontwidth = 6;
- emdp->fontdescent = 4;
- }
- else
- #endif
- if (device == bDevLaser) {
- /* LaserWriter will use 48 pt (actually 50 pt) font */
- if (courierprint) {
- emdp->normfont = monaco; /* force to use Courier rather than our font */
- emdp->highfont = monaco;
-
- TextFont(emdp->normfont);
- }
- TextSize(9);
- emdp->fontsize = 9;
- emdp->lineheight = 12;
- fontwidth = 6;
- emdp->fontdescent = 3;
- emdp->hoffset = 50;
- }
- bottommarg = (*hprec)->prInfo.rPage.bottom - (6 * emdp->lineheight);
-
- /* temporarily mark screen as all modified and all clear */
- modflg = SCRALLMOD;
- clrflg = SCRALLMOD;
-
- if (emdp->ibm_mode) {
- ibmpaintbuf(scr_map, FALSE);
- /* draw the screen but NOT the selection */
- }
- else {
- paintbuf(&emdp->charr[0], FALSE);
- /* draw the screen but NOT the selection */
- }
- PrClosePage(pport);
- }
- }
-
- PRQDABORT3:
- PrCloseDoc(pport);
-
- if ((*hprec)->prJob.bJDocLoop == bSpoolLoop && !PrError()) {
- PrPicFile(hprec, NULL, NULL, NULL, &pstat);
- }
-
- modflg = omodflg;
- clrflg = oclrflg;
- fontwidth = ofontwidth;
- emdp->normfont = ofont;
- emdp->highfont = ohighfont;
- emdp->fontsize = ofontsize;
- emdp->lineheight = olineheight;
- emdp->hoffset = ohoffset;
- emdp->voffset = ovoffset;
- emdp->fontdescent = ofontdescent;
- emdp->color = ocolor;
-
- PRQDABORT2:
- PrClose();
-
- PRQDABORT1:
- if (type == RF_PRINTSCREEN) {
- if (copyp != NULL)
- DisposPtr(copyp);
- }
- else if (type == RF_PRINTTEXT) {
- HUnlock((*emdp->texthand)->hText);
- }
- else if (type == RF_PRINTSCRAP) {
- releasescrap();
- }
- /* DisposHandle(hprec);
- hprec = NULL;
- leave it around once it's allocated */
-
- SetPort(oport);
- }
-
-
- #endif
-
- /* rlincopy-- do a special copy routine for RLIN library format records
- which converts RLIN to NOTIS format
-
- here follow the formats...
-
- A sample RLIN name authority record... book description record is the other
- important case...
-
- ID: NAF = Name Authority File
- _____________________________
- FIN HP BECKER ERNEST - Record 1.1.1
-
- ID:NAFL506215 ST:p EL:n STH:a MS:n UIP:a TD:19840322000000
- KRC:a NMU:a CRC:c UPN:a SBU:a SBC:a DID:n DF:04-08-80
- RFE:n CSC: SRU:b SRT:n SRN:n TSS: TGA:? ROM:? MOD:
- VST:d 06-08-84
- 040 DLC$cDLC
- 100 10 Becker, Ernest.
- 670 His Zen: a rational critique, 1961.
- 678 1924-1974
-
-
- All fields from ID: through MOD: are derived from a fixed field type 008
-
- 008: :NAFL506215pnana198403220000000aaca .... some fields are ignored...
- contains 40 characters, fixed length
- 0-5 date yymmdd
- 6 DID:
- 7 ROM:
- 8 blank
- 9 KRC
- 10 CRC
- 11 SBC (subject heading?)
- 12 SRT
- 13 SRN
- 14 NMU
- 15 SBU
- 16 SRU
- 17 TSS
- 18-27 undefined (blank)
- 28 TGA
- 29 RFE
- 30 blank
- 31 always 'a'
- 32 UPN
- 33 EL?
- 34-37 undefined (blank)
- 38 MOD
- 39 CSC
-
- 040: :DLC|cDLC
- 100:10:Becker, Ernest.
- 670: :His Zen: a rational critique, 1961.
- 678: :1924-1974
-
- NOTIS needs ^A (EOF) appended to the end of each field (line), CR not needed
- $ needs to be translated to |
-
-
- Questions about the RLIN record:
- what is the length of the ID: and other variable length fields?
- are the field titles invariant?
- does the number of fields vary?
-
- RLIN book record
- _________________
- FIN PN BETH, R - Cluster 1 of 1
-
- ID:UKBPGB8947110-B RTYP:c ST:p FRN: MS:p EL: AD:04-04-90
- CC:9662 BLT:am DCF:a CSC:d MOD: SNR: ATC: UD:01-01-01
- CP:enk L:eng INT: GPC: BIO: FIC:0 CON:
- PC:s PD:1990/ REP: CPI:0 FSI:0 ILC:a MEI:1 II:0
- MMD: OR: POL: DM: RR: COL: EML: GEN: BSE:
- ---> irrelevant microfilm record...
-
- 010 GB8947110
- 015 GB89-47110
- 020 070903931X :$cL11.95
- 035 (Uk)070903931x
- 040 Uk$cUk$dDLC$dCStRLIN
- 050 14 BF1566
- 082 04 133.43$220
- 100 10 Beth, Rae.
- 245 10 Hedge witch :$ba guide to solitary witchcraft /$cRae Beth.
- 260 0 London :$bHale,$c1990.
- 300 189 p. :$bill. ;$c23 cm.
- 653 Witchcraft
- 650 0 Witchcraft.
- 886 2 $2UK MARC$a016$b00#a100=NOTNAL
- 886 2 $2UK MARC$a690$b00#z21030#awitchcraft
- 886 2 $2UK MARC$a691$b00#a0001260
- :+? ^throw away third character in sub-ID field: added by RLIN but not used!
-
- MARC number NOTIS label RLIN label name of field
-
- *008/00-05 DT AD date entered on file
- 008/06 D/CODE PC type of date
- 008/07-10 DT/1 PD date 1
- 008/11-14 DT/2 (in PD with slash between: 1988/1989) date 2
- 008/15-17 PLACE CP place of publ.
- 008/18-21 ILLUS ILC illustrations
- 008/22 T/AUD INT Target audience
- 008/23 REPRO REP form of item
- 008/24-27 CONT CON nature of contents
- 008/28 GOVT GPC government publication
- 008/29 CONF CPI conference publication
- 008/30 FEST FSI Festschrift
- 008/31 INDX II index
- 008/32 ME/B MEI main entry in description
- 008/33 FICT FIC fiction
- 008/34 BIOG BIO biography
- 008/35-37 LANG L language
- 008/38 MOD MOD modified record
- 008/39 SRC CSC cataloging source
-
- *supplied by NOTIS when new record is created
- Both the RLIN & NOTIS headers have additional information which is specific to
- their systems.
-
- */
-
- rlincopy(type)
- int type;
- {
- long copylen;
- int count;
- int count2;
- int scancount;
- int slen; /* length of string */
- char * rlintext; /* src text from RLIN */
- register char * rlinp;
- Ptr notistext; /* destination text */
- register char * notisp;
- register char * tempp;
- long notislen;
- char rnum[255];
- char rsub[5];
- char rline[255];
- int firsttime = TRUE;
- int blankcount;
-
- /* RLIN name authority tags */
- char DID;
- char ROM;
- char KRC;
- char CRC;
- char SBC;
- char SRT;
- char SRN;
- char NMU;
- char SBU;
- char SRU;
- char TSS;
- char TGA;
- char RFE;
- char UPN;
- char EL;
- char MOD;
- char CSC;
- char STH;
- char UIP;
-
- /* RLIN book record tags */
- char PC;
- char PD1[50]; /* 4 byte date */
- char PD2[50]; /* 4 byte date */
- char CP[50]; /* 3 */
- char ILC[50]; /* 4 */
- char INT;
- char REPR;
- char CON[50]; /* 4 */
- char GPC;
- char CPI;
- char FSI;
- char II;
- char MEI;
- char FIC;
- char BIO;
- char LAN[50]; /* 3 */
- /* shared with NAF...
- char MOD;
- char CSC;
- */
- if (type == 'C') {
- /* clear the scrap */
- ZeroScrap();
- return;
- }
-
- if ((copylen = getselection(&rlintext)) == 0) {
- return;
- }
- rlinp = rlintext;
-
- if (!memtest((long) copylen + 2000, ©err[0])) {
- /* not enough memory for operation */
- DisposPtr(rlintext);
- return;
- }
-
- notistext = NewPtr((Size) (copylen + 2000));
- if (notistext == NULL) {
- beep();
- return;
- }
- notisp = notistext;
-
- count = copylen;
- tempp = rlintext;
- while (count--) {
- /* all CRs to NULL to terminate lines as strings */
- if (*tempp == CR)
- *tempp = '\000';
- tempp++;
- }
- count = copylen;
-
- switch (type) {
- case 'a': {
- /* RLIN name authority file record */
-
- /* skip white space */
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
-
- if (strncmp(rlinp, "ID:", 3) == 0) {
- /* RLIN ID appears at the beginning of a record...
- we must assemble a 008 line from several tagged lines at the beginning */
-
- ZeroScrap(); /* clear the old scrap, this is a new record */
- scancount = sscanf(rlinp,
- "%*s%*s EL:%c STH:%c %*s UIP:%c",
- &EL, &STH, &UIP
- );
- if (scancount != 3) {
- /* hey, wrong format! */
- beep();
- DisposPtr(notistext);
- DisposPtr(rlinp);
- return(-1);
- }
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
- scancount = sscanf(rlinp,
- "KRC:%c NMU:%c CRC:%c UPN:%c SBU:%c SBC:%c DID:%c",
- &KRC, &NMU, &CRC, &UPN, &SBU, &SBC, &DID
- );
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- MOD = ' '; /* space may be skipped by copy at end of line */
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
- scancount = sscanf(rlinp,
- "RFE:%c CSC:%c SRU:%c SRT:%c SRN:%c TSS:%c TGA:%c ROM:%c MOD:%c",
- &RFE, &CSC, &SRU, &SRT, &SRN, &TSS, &TGA, &ROM, &MOD
- );
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- sprintf(notisp, "%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c%c",
- CTLB, PT, EL, CSC, ROM, MOD, UPN, TGA, SBC, DID, TSS, SRN, SRT, NMU,
- SBU, SRU, KRC, STH, RFE, UIP, CRC);
- /* CTLB overrides pastemode in 3270 ED_PASTE, PT is Tab, need to tab to first field to start */
-
- notisp += strlen(notisp);
-
- /* skip next line */
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
- }
- break;
- }
- case 'b': {
- /* RLIN book record */
-
- /* skip white space */
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
-
- if (strncmp(rlinp, "ID:", 3) == 0) {
- /* RLIN ID appears at the beginning of a record...
- we must assemble a 008 line from several tagged lines at the beginning */
-
- ZeroScrap(); /* clear the old scrap, this is a new record */
-
- /* skip the first line */
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
- scancount = sscanf(rlinp,
- "%*s %*s %*s CSC:%c MOD:%c",
- &CSC, &MOD
- );
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
- if (scancount != 2) {
- /* hey, wrong format! */
- beep();
- DisposPtr(notistext);
- DisposPtr(rlinp);
- return(-1);
- }
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
- CON[0] = ' ';
- CON[1] = ' ';
- CON[2] = ' ';
- CON[3] = ' ';
- scancount = sscanf(rlinp,
- "CP:%c%c%c L:%c%c%c INT:%c GPC:%c BIO:%c FIC:%c CON:%4s",
- &CP[0], &CP[1], &CP[2],
- &LAN[0], &LAN[1], &LAN[2],
- &INT, &GPC, &BIO, &FIC, &CON
- );
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- CP[3] = '\000';
- LAN[3] = '\000';
- /* CON may be truncated since it's at the end of the line */
- if (CON[0] == '\000') CON[0] = ' ';
- if (CON[1] == '\000') CON[1] = ' ';
- if (CON[2] == '\000') CON[2] = ' ';
- if (CON[3] == '\000') CON[3] = ' ';
- CON[4] = '\000';
-
- PD1[4] = '\000';
- PD2[4] = '\000';
- ILC[4] = '\000';
- for ( ; *rlinp == ' '; rlinp++, count--)
- ;
- scancount = sscanf(rlinp,
- "PC:%c PD:%c%c%c%c%*c%c%c%c%c REP:%c CPI:%c FSI:%c ILC:%c%c%c%c MEI:%c II:%c",
- &PC, &PD1[0], &PD1[1], &PD1[2], &PD1[3],
- &PD2[0], &PD2[1], &PD2[2], &PD2[3],
- &REPR, &CPI, &FSI, &ILC[0], &ILC[1], &ILC[2], &ILC[3], &MEI, &II
- );
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- /* we now have the first line of the NOTIS record, so we can put it out...*/
- sprintf(notisp, "%c%c%c%c%c%c%c%c%3s%3s%c%c%c%c%4s%4s%4s%4s%c%c%c%c%c%c%c",
- CTLB, PT, PT, PT, PT, PT, PT, CSC, &CP, &LAN, MOD, INT, REPR, PC,
- &PD1, &PD2, &CON, &ILC, GPC, BIO, FSI, CPI, FIC, II, MEI);
- /* CTLB overrides pastemode in 3270 ED_PASTE, PT is Tab, need to tab to first field to start */
-
- notisp += strlen(notisp);
-
- /* skip next line */
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen; if (count < 0) break;
-
- }
- break;
- }
- default: {
- DisposPtr(notistext);
- DisposPtr(rlintext);
- return(-1);
- }
- }
- /* we continue to copy lines which have a similar format */
- while (count > 0) {
- /* now translate the remaining lines from RLIN to NOTIS format */
- blankcount = 0;
- for ( ; *rlinp == ' '; rlinp++, count--)
- blankcount++;
-
- if (strncmp(rlinp, ":+", 2) == 0)
- /* RLIN prompt is obviously the end of a record... */
- break;
-
- /* convert $ to IBM field separator */
- tempp = rlinp;
- slen = strlen(rlinp);
- while (slen--) {
- if (*tempp == '$')
- *tempp = IBMK_RS;
- tempp++;
- }
-
- if (blankcount < 4) {
- /* new field rather than continuation */
- if (!firsttime) {
- *notisp++ = IBMK_FS; /* add End of Field marker at end of previous line */
- }
- firsttime = FALSE;
-
- scancount = sscanf(rlinp, "%254s%*c%c%c%*c%254[^\000]",
- &rnum, &rsub[0], &rsub[1], &rline);
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen;
-
- sprintf(notisp, "%254s:%c%c:%254s", &rnum, rsub[0], rsub[1], &rline);
- notisp += strlen(notisp);
- }
- else {
- scancount = sscanf(rlinp, "%254[^\000]",
- &rline);
- slen = strlen(rlinp) + 1; rlinp += slen; count -= slen;
-
- sprintf(notisp, " %254s", &rline);
- notisp += strlen(notisp);
- }
- }
- *notisp++ = IBMK_FS; /* add End of Field marker at end of last line? */
-
- notislen = notisp - notistext;
-
- DisposPtr(rlintext);
-
- puttextscrap(notistext, notislen);
-
- DisposPtr(notistext);
-
- if (edresetselect)
- selreset(emdp);
-
- return(0);
- }